
use "D:\Dropbox\Work - RA\D02 - REV and MOM relationship\A01_Panel_data_WITH_US.dta", replace
cd "D:\Dropbox\Work - RA\! (2025.03.03) Final replication code for RFS"
gen con=1


* REV is multiplied by -1 (sign flip).;
replace rev=rev*(-1)
replace mktvol_mkt_dret=mktvol_ewret if missing(mktvol_mkt_dret)


* Sample period from 2000
keep if year>=2000

* Select country-months with firms with sufficient number of IO information
keep if num_country>=125


* Compute 1-IO (EW)
sum io_VW, det
capture drop one_minus_io_VW
gen one_minus_io_VW=1-io_VW
sum one_minus_io_VW

* Compute 1-IO (EW)
sum io_EW, det
capture drop one_minus_io_EW
gen one_minus_io_EW=1-io_EW
sum one_minus_io_EW

* Sort by total market cap  (MktCap)
capture drop rank_MktCap
sort year month 
astile rank_MktCap=MktCap, n(2) by(year month)
tab Country if rank_MktCap==1
tab Country if rank_MktCap==2


* Sort by {one_minus_io_EW} for all countries
capture drop noise_EW noise_EW_by_dev
sort year month	Dev_dummy
astile noise_EW=one_minus_io_EW , n(2) by(year month)
astile noise_EW_by_dev=one_minus_io_EW , n(2) by(year month Dev_dummy)


* Drop without noise_EW_by_dev
sum num_country, det
drop if missing(noise_EW)


* Momentum / Reversal profite by 1-IO median

	* 1-IO (EW) by each group 
	sort rank_MktCap noise_EW
	by rank_MktCap noise_EW: sum one_minus_io_EW, det
	sort noise_EW
	by noise_EW: sum one_minus_io_EW, det

	* Small MktCap (EW)
	eststo clear
	sum mom rev if rank_MktCap==1 & noise_EW==1
	sum mom rev if rank_MktCap==1 & noise_EW==2
	estpost ttest mom rev if rank_MktCap==1, by(noise_EW)
	esttab . using "Result_Table_6_B.csv", replace cells("N_1 N_2 mu_1 mu_2 t p") title("Small MktCap")

	* Developed (EW)
	eststo clear 
	estpost ttest mom rev if rank_MktCap==2, by(noise_EW)
	esttab . using "Result_Table_6_B.csv", append cells("N_1 N_2 mu_1 mu_2 t p") title("Large MktCap")

	* Aggregate (EW)
	eststo clear 
	estpost ttest mom rev, by(noise_EW)
	esttab . using "Result_Table_6_B.csv", append cells("N_1 N_2 mu_1 mu_2 t p") title("Aggregate")

	